    /*
     * Bjorn Carandang
     * bac37@drexel.edu
     * CS338:GUI, Assignment [P3]
     */

/*
 * CasterFarmPanel.java
 *
 * Created on Aug 24, 2010, 4:25:08 AM
 */

package root;

import java.awt.event.KeyEvent;
import javax.swing.DefaultComboBoxModel;
import javax.swing.SpinnerNumberModel;

/**
 *
 * @author Letty
 */
public class CasterFarmPanel extends javax.swing.JPanel {

    CasterDataModel CDM; 

    /** Creates new form CasterFarmPanel */
    public CasterFarmPanel(CasterDataModel cdm) {
        CDM = cdm;
        initComponents();
        this.CropComboBox.setModel(new DefaultComboBoxModel(CDM.planttypes));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel5 = new javax.swing.JLabel();
        CropComboBox = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        WaterSpinner = new javax.swing.JSpinner(new SpinnerNumberModel(0, 0, 100, 1));
        jLabel2 = new javax.swing.JLabel();
        FertilizerSpinner = new javax.swing.JSpinner(new SpinnerNumberModel(0, 0, 100, 1));
        jLabel3 = new javax.swing.JLabel();
        BugSpinner = new javax.swing.JSpinner(new SpinnerNumberModel(0, 0, 100, 1));
        jLabel4 = new javax.swing.JLabel();
        ResultField = new javax.swing.JTextField();
        ExecuteCalculationsButton = new javax.swing.JButton();

        setLayout(new java.awt.GridLayout(6, 2));

        jLabel5.setText("Crop Type");
        add(jLabel5);

        CropComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        CropComboBox.setMaximumSize(new java.awt.Dimension(500, 13));
        CropComboBox.setPreferredSize(null);
        add(CropComboBox);

        jLabel1.setText("Watering Level");
        add(jLabel1);

        WaterSpinner.setMaximumSize(new java.awt.Dimension(500, 13));
        WaterSpinner.setPreferredSize(null);
        WaterSpinner.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                WaterSpinnerFocusGained(evt);
            }
        });
        WaterSpinner.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                WaterSpinnerKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                WaterSpinnerKeyTyped(evt);
            }
        });
        add(WaterSpinner);

        jLabel2.setText("Fertilizer Level");
        add(jLabel2);

        FertilizerSpinner.setMaximumSize(new java.awt.Dimension(500, 13));
        FertilizerSpinner.setPreferredSize(null);
        add(FertilizerSpinner);

        jLabel3.setText("Bug Level");
        add(jLabel3);

        BugSpinner.setMaximumSize(new java.awt.Dimension(500, 13));
        BugSpinner.setPreferredSize(null);
        add(BugSpinner);

        jLabel4.setText("Suggested Action");
        add(jLabel4);

        ResultField.setEditable(false);
        ResultField.setMaximumSize(new java.awt.Dimension(500, 13));
        add(ResultField);

        ExecuteCalculationsButton.setText("Calculate");
        ExecuteCalculationsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ExecuteCalculationsButtonActionPerformed(evt);
            }
        });
        add(ExecuteCalculationsButton);
    }// </editor-fold>//GEN-END:initComponents

    private void WaterSpinnerKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_WaterSpinnerKeyPressed

    }//GEN-LAST:event_WaterSpinnerKeyPressed

    private void WaterSpinnerKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_WaterSpinnerKeyTyped

    }//GEN-LAST:event_WaterSpinnerKeyTyped

    private void WaterSpinnerFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_WaterSpinnerFocusGained
    
    }//GEN-LAST:event_WaterSpinnerFocusGained

    /*
     * Runs the calculations for recommended actions for a field. Will output
     * one of three actions given a farm's current state (crop type, fert,
     * water, and bug infestation.
     */
    private void ExecuteCalculationsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExecuteCalculationsButtonActionPerformed
                     ResultField.setText(this.CDM.GetFarmAction((Integer) this.WaterSpinner.getValue(),
                     (Integer) this.FertilizerSpinner.getValue(),
                     (Integer) this.BugSpinner.getValue(),
                     (String) this.CropComboBox.getSelectedItem()));
    }//GEN-LAST:event_ExecuteCalculationsButtonActionPerformed



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JSpinner BugSpinner;
    private javax.swing.JComboBox CropComboBox;
    private javax.swing.JButton ExecuteCalculationsButton;
    private javax.swing.JSpinner FertilizerSpinner;
    private javax.swing.JTextField ResultField;
    private javax.swing.JSpinner WaterSpinner;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    // End of variables declaration//GEN-END:variables

}
